package it.polimi.traveldream.ejb.usermanagement;

import it.polimi.traveldream.ejb.usermanagement.dto.UserDTO;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;


/**
 * Entity implementation class for Entity: UserEntity
 *
 */
@Entity
@Table(name="users")
@NamedQueries({
	@NamedQuery(name=User.FIND_ALL,
				query="SELECT u FROM User u")
})
public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "User.findAll";
	   
	@Id
	private String userID;

	private int cittaID;

	private String cognome;

	@Temporal(javax.persistence.TemporalType.TIMESTAMP)
	private Date datanascita;

	private String email;

	private String genere;

	private String nome;

	private String password;

	@ElementCollection(targetClass = Group.class)
    @CollectionTable(name = "user_group",
                    joinColumns = @JoinColumn(name = "UserID"))
    @Enumerated(EnumType.STRING)
    @Column(name="GroupID")
    private List<Group> groups;
	
	public User() {
		super();
	}

	public User(UserDTO user){
        
		this.userID		  = user.getUserid();
		this.cittaID		  = user.getCittaid();
        this.datanascita        = user.getDatanascita();
        this.genere        = user.getGenere();
        this.email        = user.getEmail();
        this.cognome    = user.getCognome();
        this.nome     = user.getNome();        
        this.password     = user.getPassword() ;
    }
	
	public String getUserID() {
		return this.userID;
	}

	public void setUserID(String userID) {
		this.userID = userID;
	}

	public int getCittaID() {
		return this.cittaID;
	}

	public void setCittaID(int cittaID) {
		this.cittaID = cittaID;
	}

	public String getCognome() {
		return this.cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public Date getDataNascita() {
		return this.datanascita;
	}

	public void setDatanascita(Date datanascita) {
		this.datanascita = datanascita;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getGenere() {
		return this.genere;
	}

	public void setGenere(String genere) {
		this.genere = genere;
	}

	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

    public List<Group> getGroups() {
        return groups;
    }
 
    public void setGroups(List<Group> groups) {
        this.groups = groups;
    }

    @Override
    public String toString() {
    	return "DA FARE!!!!";
    }
}